<template>
  <main>
    <div class="container">
      <h1>欢迎使用TODO待办事件</h1>
      <!-- 添加todo -->
      <TodoAdd :tid="todos.length" @addTodo="addTodo" />
      <!-- 根据条件过滤todos -->
      <TodoFilter
        :selected="filterCondition"
        @changeFilterCondition="changeFilterCondition($event)"
      />
      <!-- 展示todos -->
      <TodoList :todos="filteredTodos" />
    </div>
  </main>
</template>

<script>
import TodoAdd from "@/components/TodoAdd.vue";
import TodoFilter from "@/components/TodoFilter.vue";
import TodoList from "@/components/TodoList.vue";
// 封装的js业务逻辑
import useTodos from "@/hooks/useTodos";
import useFilteredTodos from "@/hooks/useFilteredTodos";

export default {
  name: "App",
  components: { TodoAdd, TodoFilter, TodoList },
  setup() {
    // 调用封装的js内容
    const { todos, addTodo } = useTodos();
    const { filterCondition, filteredTodos, changeFilterCondition } =
      useFilteredTodos(todos);

    return {
      todos,
      addTodo,
      filterCondition,
      filteredTodos,
      changeFilterCondition,
    };
  },
};
</script>

<style>
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: Helvetica, "PingFang SC", "Microsoft Yahei", sans-serif;
}

main {
  width: 100vw;
  min-height: 100vh;
  display: grid;
  align-items: center;
  justify-items: center;
  background-color: rgb(203, 210, 240);
}

.container {
  width: 60%;
  max-width: 400px;
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.15);
  border-radius: 24px;
  padding: 48px 24px;
  background-color: rgb(245, 246, 252);
}

h1 {
  margin-bottom: 24px;
  text-align: center;
  font-size: 24px;
  color: #414873;
}
</style>
